package br.ufrgs.inf.engsoft.stp.product;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.ufrgs.inf.engsoft.stp.user.User;

@SuppressWarnings("serial")
@Entity
@Table(name = "stp_product")
public class Product implements Comparable<Product>, Serializable {
	
	public static final String PROPERTY_NAME = "name";
	public static final String PROPERTY_CATEGORY = "category.name";
	public static final String PROPERTY_VALUE = "value";
	public static final String PROPERTY_ENABLE = "enable";
	public static final int ENABLE = 1;
	public static final int NOT_ENABLE = 0;
	
	@Id
	@Column(name = "id", unique = true, nullable = false)
	private Long id;
	
	@Column(name = "name", nullable = false)
	private String name;
	
	@ManyToOne
    @JoinColumn(name = "category_id", nullable = false)
	private Category category;
	
	@Column(name = "value")
	private String value;
	
	@ManyToOne
    @JoinColumn(name = "user_cpf", nullable = false)
	private User user;
	
	@Column(name = "image_url")
	private String imageURL;
	
	@Column(name = "enable", nullable = false)
	private Integer enable;
	
	@Column(name = "exchange_id")
	private Long exchangeId;
	
	public Product() {
		this.id = (new Date()).getTime();
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Category getCategory() {
		return category;
	}
	
	public void setCategory(Category category) {
		this.category = category;
	}
	
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	
	public Integer getEnable() {
		return enable;
	}
	
	public void setEnable(Integer enable) {
		this.enable = enable;
	}

	public String getImageURL() {
		return imageURL;
	}

	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	public Long getId() {
		return id;
	}

	public Long getExchangeId() {
		return exchangeId;
	}

	public void setExchangeId(Long exchangeId) {
		this.exchangeId = exchangeId;
	}

    @Override
    public int compareTo(Product o) {
        return this.id.compareTo(o.getId());
    }
}
